package com.irdstudio.efp.console.api.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.irdstudio.efp.console.service.facade.SUserDutyService;
import com.irdstudio.efp.console.service.vo.SUserDutyVO;
import com.irdstudio.efp.console.service.vo.SUserOrgByDutyIdVO;
import com.irdstudio.efp.e4a.service.facade.SRoleDataRuleService;
import com.irdstudio.basic.framework.core.constant.ResponseData;
import com.irdstudio.basic.framework.web.controller.AbstractController;

@RestController
@RequestMapping("/api")
public class SUserDutyController extends AbstractController  {

	@Autowired
	@Qualifier("sUserDutyService")
	private SUserDutyService sUserDutyService;

	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;

	/**
	 * 列表数据查询
	 */
	@RequestMapping(value="/s/user/dutys", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<SUserDutyVO>> querySUserDutyAll(
			@RequestBody SUserDutyVO vo) {
		setUserInfoToVO(vo);
		// 根据用户角色获取用户权限方案
		/**【暂时不需要】
		 * String dataAuthority = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		List<SUserDutyVO> outputVo = null;
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataAuthority);*/

		// 根据权限方案调用不同的方案进行数据查询
		List<SUserDutyVO> outputVo = sUserDutyService.queryAllOwner(vo);

		/**【不符合switch规范用法】
		 * switch (dataRuleType) {
		case Owner:
			outputVo = sUserDutyService.queryAllOwner(vo);
			break;

		default:
			outputVo = sUserDutyService.queryAllOwner(vo);
			break;
		}*/
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键查询详情
	 */
	@RequestMapping(value="/s/user/duty/{userCode}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<SUserDutyVO> queryByPk(@PathVariable("userCode") String userCode) {
		SUserDutyVO inVo = new SUserDutyVO();
				inVo.setUserCode(userCode);
		SUserDutyVO outputVo = sUserDutyService.queryByPk(inVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键查询详情
	 */
	@RequestMapping(value="/s/user/duty/list/{userCode}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<List<SUserDutyVO>> queryList(@PathVariable("userCode") String userCode) {
		SUserDutyVO inVo = new SUserDutyVO();
		inVo.setUserCode(userCode);
		List<SUserDutyVO> outputVo = sUserDutyService.queryList(inVo);
		return getResponseData(outputVo);

	}

    /**
     * 根据主键查询详情
     */
    @RequestMapping(value="/s/user/duty/listbyduty/{dutyCode}", method=RequestMethod.GET)
    public @ResponseBody ResponseData<List<SUserDutyVO>> queryByDuty(@PathVariable("dutyCode") String dutyCode) {
        SUserDutyVO inVo = new SUserDutyVO();
        inVo.setDutyCode(dutyCode);
        List<SUserDutyVO> outputVo = sUserDutyService.queryList(inVo);
        return getResponseData(outputVo);

    }

	/**
	 * 根据主键删除信息
	 */
	@RequestMapping(value="/s/user/duty", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody SUserDutyVO inSUserDutyVo) {
		int outputVo = sUserDutyService.deleteByPk(inSUserDutyVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键更新信息
	 */
	@RequestMapping(value="/s/user/duty", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody SUserDutyVO inSUserDutyVo) {
		int outputVo = sUserDutyService.updateByPk(inSUserDutyVo);
		return getResponseData(outputVo);

	}

	/**
	 * 新增数据
	 */
	@RequestMapping(value="/s/user/duty", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertSUserDuty(@RequestBody SUserDutyVO inSUserDutyVo) {
		int outputVo = sUserDutyService.insertSUserDuty(inSUserDutyVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据岗位码查询当前岗位下所有的用户信息
	 */
	@RequestMapping(value="/s/user/duty/users", method=RequestMethod.GET)
	public @ResponseBody ResponseData<List<SUserOrgByDutyIdVO>> queryUsersByDuty(
			@RequestParam("dutyCode") String dutyCode,
			@RequestParam("legalOrgCode") String legalOrgCode) {
		SUserDutyVO inVo = new SUserDutyVO();
		inVo.setDutyCode(dutyCode);
		List<SUserOrgByDutyIdVO> outputVo = sUserDutyService.queryUsersByDuty(inVo);
		return getResponseData(outputVo);
	}

	/**
	 * 根据岗位码查询当前岗位下所有的用户信息
     * create by luzy 2019/10/11
     * description  SUserDutySelecter
	 */
	@RequestMapping(value="/s/user/duty/users", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<SUserOrgByDutyIdVO>> querySUsersByDuty
			(@RequestBody SUserDutyVO sUserDutyVO) {
		SUserDutyVO inVo = new SUserDutyVO();
		inVo.setDutyCode(sUserDutyVO.getDutyCode());
		List<SUserOrgByDutyIdVO> outputVo = sUserDutyService.queryUsersByDuty(inVo);
		return getResponseData(outputVo);
	}
}
